﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Srv3CodeTool
{
    public partial class FrmNewLua : Form
    {
        public FrmNewLua()
        {
            InitializeComponent();
        }

        private void btnCancle_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                Functions func = new Functions();
                func.AddLuaScriptByMode(rdbLua.Checked, cmbModuleSet.SelectedItem.ToString(), txtBlock.Text.ToString(), rtxNewLua.Text.ToString());

                Functions.ShowMsgBox("Lua脚本添加成功", MSGBOX_TYPE.MSGBOX_TYPE_INFO);
                Log.LogSave("Lua脚本添加成功", LOGTYPE.LOGTYPE_INFO);
                rtxNewLua.Clear();
             }
            catch (System.Exception ex)
            {
                Log.LogSave(ex.ToString(), LOGTYPE.LOGTYPE_ERROR);
            }
        }

        private void FrmNewLua_Load(object sender, EventArgs e)
        {
            try
            {
                Functions func = new Functions();
                // 模块列表
                object[] objModuleArr = func.GetModuleArray();
                cmbModuleSet.Items.AddRange(objModuleArr);
                cmbModuleSet.SelectedIndex = 0;

                rdbLua.Checked = true;
            }
            catch (System.Exception ex)
            {
                Log.LogSave(ex.ToString(), LOGTYPE.LOGTYPE_ERROR);
            }
        }

        private void txtBlock_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((int)e.KeyChar <= 32) // 特殊键(含空格), 不处理 
            { 
                return; 
            } 
            if (!char.IsDigit(e.KeyChar)) // 非数字键, 放弃该输入 
            { 
                e.Handled = true; 
                return; 
            }
        }

    }
}